﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Public;
using System.Globalization;

namespace WebsiteAdmin.Wilson.LinkInfo.Handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Create : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int rtn = 0;
            if (Cookie.AdminLoginName != null || Cookie.AdminLoginName != "")
            {
                string txbLinkTitle = context.Request["LinkTitle"].Trim();					//介绍标题
                string txbLinkURL = context.Request["LinkURL"].Trim();					//介绍标题
                int txbSortBy = Convert.ToInt32(context.Request["SortBy"].Trim(), CultureInfo.InvariantCulture);	//显示顺序

                rtn = DoInsert(
                    txbLinkTitle,
                    txbLinkURL,
                    txbSortBy
                );
            }
            context.Response.Write((rtn == 1) ? "{ \"Done\": \"Success\" }" : "{ \"Done\": \"Failed\" }");
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private static int DoInsert(
                string txbLinkTitle,
                string txbLinkURL,
                int txbSortBy
            )
        {
            return
                Bll.Link.Insert(
                    Global.ConnWilson,
                    txbLinkTitle,
                    txbLinkURL,
                    txbSortBy
                );
        }
    }
}
